﻿#include "mainwindow.h"
#include <QApplication>
#include <QTranslator>
#include <QDir>
#include <QFileInfo>

QString getQmlPath()
{
	QString appDir = QCoreApplication::applicationDirPath();
	QDir currentDir(appDir);

	QString qmlFilePath = QDir::cleanPath(currentDir.absolutePath() + QDir::separator() +
		QString("mui") + QDir::separator() +
		QString("zh_CN") + QDir::separator() +
		QString("translate_zh.qm")
	);

	if (QFile::exists(qmlFilePath))
	{
		return qmlFilePath;
	}

	return QString();
}

QString getRibbonTranslationPath() 
{
	QString appDir = QCoreApplication::applicationDirPath();
	QString filePath = QDir::cleanPath(
		appDir + "/mui/translate_zh.qm" 
	);
	qDebug() << "动态库翻译文件路径：" << filePath;
	return QFile::exists(filePath) ? filePath : QString();
}

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);
	QTranslator translator;
	if (translator.load(getQmlPath()))
	{
		a.installTranslator(&translator);
	}
	QTranslator ribbonTranslator;
	if (ribbonTranslator.load(getRibbonTranslationPath())) 
	{
		a.installTranslator(&ribbonTranslator);  
		qDebug() << "动态库翻译加载成功";
	}
	else {
		qWarning() << "动态库翻译加载失败，路径不存在或文件错误";
	}
	MainWindow w;
	w.show();
	return a.exec();
}